/**
 * 
 */
package sv.gob.mtps.hr.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sv.gob.mtps.hr.model.CatParentesco;
import sv.gob.mtps.hr.model.CatPorcentajeBeneficio;
import sv.gob.mtps.hr.model.EmpParentVw;
import sv.gob.mtps.hr.model.SferhEmpleadoXCatParentesco;

/**
 * @author julio.perez
 *
 */

@Repository
public class EmpleadoXCatParentescoDAOImpl implements EmpleadoXCatParentescoDAO {
	
	@Autowired
	SessionFactory sessionFactory;

	/* (non-Javadoc)
	 * @see sv.gob.mtps.hr.dao.EmpleadoXCatParentescoDAO#addParent(sv.gob.mtps.hr.model.SferhEmpleadoXCatParentesco)
	 */
	@Override
	public void addParent(SferhEmpleadoXCatParentesco parent) {
		this.sessionFactory.getCurrentSession().save(parent);

	}

	/* (non-Javadoc)
	 * @see sv.gob.mtps.hr.dao.EmpleadoXCatParentescoDAO#updateParent(sv.gob.mtps.hr.model.SferhEmpleadoXCatParentesco)
	 */
	@Override
	public void updateParent(SferhEmpleadoXCatParentesco parent) {
		this.sessionFactory.getCurrentSession().update(parent);
		
	}

	/* (non-Javadoc)
	 * @see sv.gob.mtps.hr.dao.EmpleadoXCatParentescoDAO#listParent()
	 */
	@Override
	public List<SferhEmpleadoXCatParentesco> listParent() {
		// TODO Auto-generated method stub
		return this.sessionFactory.getCurrentSession().createQuery("from SferhEmpleadoXCatParentesco").list();
	}

	/* (non-Javadoc)
	 * @see sv.gob.mtps.hr.dao.EmpleadoXCatParentescoDAO#removeParent(java.lang.Integer)
	 */
	@Override
	public void removeParent(Integer id) {
		SferhEmpleadoXCatParentesco parent = (SferhEmpleadoXCatParentesco) this.sessionFactory.getCurrentSession().load(SferhEmpleadoXCatParentesco.class, id);
		if(parent != null){
			this.sessionFactory.getCurrentSession().delete(parent);
		}
	}

	@Override
	public List<CatParentesco> listParentesco() {
		// TODO Auto-generated method stub
		return this.sessionFactory.getCurrentSession().createQuery("from CatParentesco").list();
	}

	@Override
	public List<CatPorcentajeBeneficio> listBeneficio() {
		// TODO Auto-generated method stub
		return this.sessionFactory.getCurrentSession().createQuery("from CatPorcentajeBeneficio").list();
	}

	@Override
	public List<EmpParentVw> listParent(Integer id) {
		// TODO Auto-generated method stub
		return this.sessionFactory.getCurrentSession().createQuery("from EmpParentVw where id.idEmpleado="+id).list();
	}

}
